import os

from flask import Flask
from flask import request, render_template

templates = {}


def run_server(dir="./"):
    return


def read_files(dir):
    thisdir = os.getcwd()

    # r=root, d=directories, f = files
    for r, d, f in os.walk(thisdir):
        for file in f:
            if ".docx" in file:
                print(os.path.join(r, file))
                templates[:file.index(".")] = os.path.join(r, file)

    print(templates)


def start_flask_server():
    app = Flask(__name__)

    @app.route('{template}')
    def serve_template():
        template = request.match_info['user']
        if template in templates:
            return render_template(templates[template])
        return 404
